//content_category_detail

exports.content_category_detail = function (req, res) {

    //获取body参数
    var bodyParams = req.routeInfo.bodyParams;

    //最终结果
    var resultData = {};

    var skip = bodyParams.skip == undefined ? 0 : bodyParams.skip;

    var limit = bodyParams.limit == undefined ? config.publicConfig.LIMIT : bodyParams.limit;

  
    //任务流创建
    async.waterfall([

            function (cb) {
                var search = bodyParams.search;
                if (search == 1) {
                    //浏览量倒序（热门）
             
                   R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.forumContentCategoryDetail + "/fc_fcfid/" + bodyParams.art_category + "/sort_order/fc_browse_count-desc/skip/" + skip + "/limit/" + limit,
                            method: 'POST',
                            data : {
                                fields : [
                                    "fc_id",
                                    "fc_fcid",
                                    "fc_uid",
                                    "fc_title",
                                    "fc_images",
                                    "fc_type",
                                    "fc_sort",
                                    "fc_browse_count",
                                    "fc_answer_count",
                                    "fc_fcfid",
                                    "fc_utype",
                                    "afc_id",
                                    "fc_fid",
                                    "fc_name",
                                    "fc_icon",
                                    "u_id",
                                    "u_type",
                                    "u_nickname",
                                    "u_header_url",
                                    "is_delete",
                                    "fc_create_time",
                                    "fc_content"
                                ].join(",")
                            }
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.articleData = data.data;
                            cb();
                        }
                    );
                } else if (search == 2) {
                    //时间倒序（最新）
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.forumContentCategoryDetail + "/fc_fcfid/" + bodyParams.art_category + "/sort_order/fc_create_time-desc/skip/" + skip + "/limit/" + limit,
                            method: 'GET'
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.articleData = data.data;
                            cb();
                        }
                    );
                } else if (search == 3) {
                    //艺问答
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.forumContentCategoryDetail + "/fc_type/0/fc_fcfid/" + bodyParams.art_category + "/sort_order/fc_create_time-desc/skip/" + skip + "/limit/" + limit,
                            method: 'GET'
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.articleData = data.data;
                            cb();
                        }
                    );
                } else if (search == 4) {
                    //谈一谈
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.forumContentCategoryDetail + "/fc_type/1/fc_fcfid/" + bodyParams.art_category + "/sort_order/fc_create_time-desc/skip/" + skip + "/limit/" + limit,
                            method: 'GET'
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.articleData = data.data;
                            cb();
                        }
                    );
                } else if (search == 5) {
                    //艺堂课
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.forumContentCategoryDetail + "/fc_type/2/fc_fcfid/" + bodyParams.art_category + "/sort_order/fc_create_time-desc/skip/" + skip + "/limit/" + limit,
                            method: 'GET'
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.articleData = data.data;
                            cb();
                        }
                    );
                } else {
                    cb();
                }


            }
        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

};